package com.gin.no_gay_alliance.fragment.daily;

import android.util.Log;

import com.gin.jackson.utils.ObjectUtils;
import com.gin.nga.response.body.nuke.FollowUserListBody;
import com.gin.no_gay_alliance.adpter.follow.FollowUserAdapter;
import com.gin.no_gay_alliance.app.MyApplication;
import com.gin.no_gay_alliance.callback.Callback;
import com.gin.no_gay_alliance.databinding.FragmentDailyFollowUserBinding;
import com.gin.no_gay_alliance.fragment.base.BaseBindingFragment;

/**
 * 关注列表
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/13 09:56
 **/
public class FollowUserFragment extends BaseBindingFragment<FragmentDailyFollowUserBinding> implements Callback<FollowUserListBody> {
    int page = 1;
    boolean hasNext = true;
    private FollowUserAdapter adapter;

    /**
     * onCreateView 的后续操作
     */
    @Override
    protected void onCreateView() {
        page = 1;
        Log.d(TAG, "onCreateView: " + "关注列表");
        adapter = new FollowUserAdapter(requireContext());
        b.recyclerView.setAdapter(adapter);
    }

    @Override
    public void onResume() {
        super.onResume();
        sendRequest();
    }

    /**
     * 请求成功回调
     *
     * @param data 数据
     */
    @Override
    public void onSuccess(FollowUserListBody data) {
        if (ObjectUtils.isEmpty(data.getData())) {
            Log.d(TAG, "关注列表加载完毕");
            hasNext = false;
            return;
        }
        page++;
        // 更新数据
        ui(() -> adapter.pushData(data.getData().values()));
        sendRequest();
    }

    private void sendRequest() {
        MyApplication.app.managerFactory.getFollowManager().followGet(page, this);
    }
}
